//
//  MenuButtonView.m
//  DaMaoMall
//
//  Created by HXHL-wally on 16/7/25.
//  Copyright © 2016年 daMao-wally. All rights reserved.
//

#import "MenuButtonView.h"

@implementation MenuButtonView

+(instancetype)MenuButtonViewWithFarme:(CGRect)farme delegate:(id<MenuButtonViewDelegate>)delegate ImageURLStringsGroup:(NSArray *)imgUrlArray titlesGroup:(NSArray *)titlesArray{
    
    MenuButtonView * view =[[MenuButtonView alloc]initWithFrame:farme];
    view.backgroundColor = [UIColor whiteColor];
    for (int i = 0; i < imgUrlArray.count; i++) {
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(GetScreenWidth/3.125*i+30, 25, GetScreenWidth/3-45, GetScreenWidth/3-45);
        [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",imgUrlArray[i]]] forState:UIControlStateNormal];
        button.tag = 2000+i;
        [button addTarget:view action:@selector(menuButtonAtTag:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
        
        UILabel * label = [[UILabel alloc ]initWithFrame:CGRectMake(CGRectGetMinX(button.frame), GetScreenWidth/3-20, 80, 20)];
        label.text = titlesArray[i];
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = NSTextAlignmentCenter;
        [view addSubview:label];
    }
    return view;
}

#pragma mark - 点击按钮执行代理方法
- (void)menuButtonAtTag:(UIButton *)tag
{
    [self.menuButtonViewDelegate didSelectButtonAtIndex:tag.tag];
}

@end
